package makeGood;

import java.util.Stack;

public class Solution {
    public String makeGood(String s) {
        // 栈
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            if(!stack.isEmpty()){
                if(check(s.charAt(i),stack.peek())){
                    stack.pop();
                }else {
                    stack.push(s.charAt(i));
                }
            } else {
                stack.push(s.charAt(i));
            }
        }
        StringBuilder sb = new StringBuilder();
        while (!stack.isEmpty()){
            sb.append(stack.pop());
        }
        return sb.reverse().toString();
    }
    private boolean check(char a,char b){
        return (a<b&&Character.toLowerCase(a) == b)||(a>b&&Character.toLowerCase(b) == a);
    }
}
